import { configure } from "log4js";
import { ETL, ExtractOPGG, LoadOPGG, OPGGBasicModule, OPGGModule, StratReptile, TransformHeroImg, TransformInterface, TransformMatchCline, TransformPiple, TransformSkill, TransoformSpell } from "./reptile";
import { ConfigInterface, connecDB } from "./utils";
import { qiniu } from "./utils/qiniuLoad";

export async function serve(config: ConfigInterface) {
    if (config.logger) configure(config.logger)
    const { dbName, dbUrl, access, secret, bucket, map } = config
    const dbConeect = new connecDB(dbUrl, dbName)

    const qiniuLoad = new qiniu(access, secret, bucket)

    const opggBasic = await dbConeect.mongoCol<OPGGBasicModule>('basicQueue');
    const opggCol = await dbConeect.mongoCol<OPGGModule>('opgg')
    const imgQueue = await dbConeect.mongoCol<{ _id: string, url: string }>('imgQueue')
    const imgCol = await dbConeect.mongoCol<{ _id: string, url: string }>('img')
    const basicQueue = new StratReptile(opggBasic);
    const extract = new ExtractOPGG()
    const transforms = new TransformPiple(
        new TransformMatchCline(),
        new TransoformSpell(),
        new TransformSkill(),
        new TransformHeroImg()
    )
    const load = new LoadOPGG(opggCol, imgQueue)
    const etl = new ETL(basicQueue, extract, transforms, load, opggBasic, imgCol, imgQueue, qiniuLoad)
    etl.etl(map)
}